package com.eee.xiang.disruptor.produce;

import com.eee.xiang.disruptor.event.Trade;
import com.lmax.disruptor.EventTranslator;
import com.lmax.disruptor.dsl.Disruptor;

import java.util.Random;

/**
 * @author eee_xiang
 * @Date 2020/5/22
 * @description
 */
public class TradePublisher {

    private Disruptor<Trade> disruptor;

    public TradePublisher(Disruptor<Trade> disruptor) {
        this.disruptor = disruptor;
    }

    public void publishData(){
        disruptor.publishEvent(new TradeEventTranslator());
    }

    class TradeEventTranslator implements EventTranslator<Trade>{

        private Random random = new Random();

        @Override
        public void translateTo(Trade event, long sequence) {
            event.setId(String.valueOf(random.nextInt(10)));
            event.setName("eee_xiang_"+random.nextInt(10));
        }
    }
}
